<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
 
<div style="margin:20px 0;"></div>
<div class="easyui-panel" >
	<div style="padding:10px 60px 20px 60px">
    <form id="translimitForm"  name="translimitForm" method="post" >
    	<input type="hidden" id="limit_uuid" name="limit_uuid" value="${transLimit.limit_uuid}"/>
    	<input type="hidden" id="channel_no" name="channel_no" value="${transLimit.channel_no}"/>    	
    	<table cellpadding="5" style="width:100%">
    		<tr>
    			<td>限额类型:</td>
    			<td><code:codeSelect id="limit_type" name="limit_type" code_type="limit_type" showSelect="false" selectId="${transLimit.limit_type}"></code:codeSelect></td>
    			<td>限额索引:</td>
    			<td><input class="easyui-textbox" type="text"  id="limit_idx" name="limit_idx" value="${transLimit.limit_idx}" data-options=""/></td>      	     			
    		</tr>    		
    		<tr>
    			<td>当日限额(元):</td>
    			<td><input class="easyui-textbox" type="text"  id="limit_amount" name="limit_amount" value="${transLimit.limit_amount}" data-options="required:true,validType:['limitamount']"/>
    			</td>
    			<td>通道编号:</td>
    			<td><input class="easyui-textbox" type="text" readonly="readonly" id="channelno" value="${transLimit.channelno}" data-options=""/>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="selelctChn">选择</a>
    			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-clear" id="clearChn">清除</a></td> 
    		</tr>   		
    		<tr>
    			<td>营业日期:</td>
    			<td><input id="begdate" name="begdate" type="text" class="easyui-datebox" value="${transLimit.begdate}" required="required" data-options="required:true,editable:false"></td>
    			<td>停业日期:</td>
    			<td><input id="enddate" name="enddate" type="text" class="easyui-datebox" value="${transLimit.enddate}" required="required" data-options="required:true,editable:false,validType:['equaldDate[\'#begdate\']']"></td>
    		</tr>   		
    		<tr>   	
    			<td>营业时间:</td>
		    	<td><input id="begtime" name="begtime" class="easyui-timespinner" style="width:80px;"  value="${transLimit.begtime}" required="required" data-options="editable: false,min:'00:00',showSeconds:true">	</td>		
    			<td>停业时间:</td>
		    	<td><input id="endtime" name="endtime" class="easyui-timespinner" style="width:80px;"  value="${transLimit.endtime}" required="required" data-options="editable: false,min:'00:00',showSeconds:true,validType:['equaldTime[\'#begtime\']']">	</td>    	     			  	     			
    		</tr>    		       		  	    		
    		<tr>
    			<td>限额状态:</td>
    			<td><code:codeSelect id="limit_st" name="limit_st" code_type="limit_st" showSelect="false" selectId="${transLimit.limit_st}"></code:codeSelect>
    			</td>     			      	     			
    		</tr>	   		 		  		    		 
    	</table>
    
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-save" id="saveBtn">保存</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton btn" iconCls="icon-back" onclick="back()">返回</a>
	    </div>
    </form>
    </div>
</div>

<div id="dialogChn">
	<div style="padding:3px" class="easyui-panel datagrid-toolbar">
		<div>
			<span>通道编号:</span>
			<input id="chn_no" type="text" name="chn_no"  class="easyui-textbox"  >					
		 	<a href="#" class="easyui-linkbutton btn"   onclick="chnSearch() ">查询</a>
		 	<a href="#" class="easyui-linkbutton btn" onclick="resetPara() ">重置</a>
		</div>	 
	</div>
    <table id="tableChn">			 
	</table>
	
</div>

<script>
$(document).ready(function() {
	$("#dialogChn").attr("style", "display: none;");
	$.extend($.fn.validatebox.defaults.rules, {		
		limitamount: {     
            validator: function(value){                                
                 return /^(?=([0-9]{1,14}$|[0-9]{1,14}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);  
            },     
            message: '格式不符或长度超限'     
        },
        transamount: {     
            validator: function(value){                                 
                 return /^(?=([0-9]{1,14}$|[0-9]{1,14}\.))(0|[1-9][0-9]*)(\.[0-9]{1,2})?$/.test(value);  
            },     
            message: '格式不符或长度超限'     
        },
        equaldDate: {  
            validator: function (value, param) {  
                var start = $(param[0]).datebox('getValue');  //获取开始时间    
                return value >= start;                             //有效范围为当前时间大于开始时间    
            },  
            message: '停业日期应大于等于营业日期'                     //匹配失败消息  
        },
        equaldTime: {  
            validator: function (value, param) {  
                var start = $(param[0]).timespinner('getValue');  //获取开始时间    
                return value >= start;                             //有效范围为当前时间大于开始时间    
            },  
            message: '停业时间应大于等于营业时间'                     //匹配失败消息  
        }
	});
	
	checkLimitIdx();
	var grid;
	$("#selelctChn").click(function(){
		grid = $("#tableChn").jpgrid({
			url: "../channelinf/getChannelInfListJson.do",
			columns: [
				{title: "通道编号", field: "CHANNEL_NO",width:100},
				{title: "通道名称", field: "CHN_NM"},
				{title: "通道类型", field: "CHN_TP",width:100},
				{title: "通道对应表", field: "CHN_PRMTB"},
				{title: "交易频率", field: "TRANS_INTERVAL",width:80}
			]
		});
		openModal("#dialogChn", {width:800, height:400,title:"选择通道"}, saveChn);
		
	})	
	
	/*清除通道编号*/
	$("#clearChn").click(function(){
		$("#channel_no").val("");
		$("#channelno").textbox("setValue", "");
	})
	
	$("#saveBtn").click(function(){			
		if($("#translimitForm").form("validate")){				
			var options ={   
		            url:'../translimit/checkTransLimit.do',   
		            type:'post',                    
		            success:function(data){
		            	  var result=data;		            	  
						  if("success"==result){					  
							  //表单提交的方法、比如ajax提交
					    	  $("#translimitForm").attr("action","../translimit/saveTransLimit.do?");
					    	  document.getElementById("translimitForm").submit();  						  
						  }else{
							  $.jpmessage.info('同一限额类型下限额索引不能重复!');
						  }
		            }   
		         };
			$("#translimitForm").ajaxSubmit(options);  
		}
		
	});
	$("body").keydown(function() {
        if (event.keyCode == "13") {//keyCode=13是回车键
            $('#saveBtn').click();
        }
    });
	
	function splitStr(str, s) {
        var newStr = "";
        var strArray = str.split(s);
        for (var i = 0; i < strArray.length; i++) {
            newStr += strArray[i];
        }
        return newStr;
    }
	
})

function resetPara(){		
	$("#chn_no").textbox("setValue", "");				
}
	 
function chnSearch() {	 
	grid.load({
		channel_no: $('#chn_no').val()						
	});
} 

function saveChn(){
	return commonsave("tableChn","channel_no","channelno","dialogChn");	
}

function commonsave(tableid,id,name,dialog){	
	var rows = $('#'+tableid).datagrid('getSelections');	
	if(rows.length==0){					
		$.jpmessage.warning('请至少选择一条记录!');		
 		return false;
	}
	if(rows.length>1){			
		$.jpmessage.warning('只能选择一条记录!');
		return false;
	}
	
	$("#"+id).val(rows[0].CHANNEL_NO);						
	$("#"+name).textbox("setValue", rows[0].CHANNEL_NO+"-"+rows[0].CHN_NM);
		
	return;
}

function checkLimitIdx(){
	var limit_uuid=$("#limit_uuid").val();
	if(limit_uuid!=""){
		$("#limit_idx").textbox('textbox').attr('readonly',true);
	}
}
</script>